package com.casic.license.view;

import javax.swing.*;
import java.awt.*;
import java.util.HashMap;
import java.util.Map;

/**
 * class description
 *
 * @author 朱宗刚
 * @version 1.0.0
 * @date 2020/7/22
 */

public class LicenseWindow extends JFrame {
    public void init() {
        this.setLayout(null);
        JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 5));
        JLabel label = new JLabel("公司名称");
        panel.add(label);
        JTextField textField = new JTextField(32);
        panel.add(textField);
        comps.put("companyName", textField);
        label = new JLabel("有效期");
        panel.add(label);
        textField = new JTextField(6);
        comps.put("validDate", textField);
        panel.add(textField);
        JComboBox<String> comboBox = new JComboBox<>();
        comboBox.addItem("天");
        comboBox.addItem("周");
        comboBox.addItem("月");
        comboBox.addItem("年");
        panel.add(comboBox);
        comps.put("unit", comboBox);
        label = new JLabel("版本");
        textField = new JTextField(6);
        panel.add(label);
        panel.add(textField);
        comps.put("version", textField);
        panel.setBounds(10, 5, 760, 30);
        this.add(panel);

        panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
        JCheckBox checkBox = new JCheckBox("数据血缘");
        panel.add(checkBox);
        comps.put("blood", checkBox);
        checkBox = new JCheckBox("数据资产");
        panel.add(checkBox);
        comps.put("asset", checkBox);
        checkBox = new JCheckBox("数据服务");
        panel.add(checkBox);
        comps.put("server", checkBox);
        checkBox = new JCheckBox("数据质量");
        panel.add(checkBox);
        comps.put("quality", checkBox);
        checkBox = new JCheckBox("用户中心");
        panel.add(checkBox);
        comps.put("user", checkBox);
        checkBox = new JCheckBox("任务调度");
        panel.add(checkBox);
        comps.put("schedule", checkBox);
        checkBox = new JCheckBox("元数据");
        panel.add(checkBox);
        comps.put("meta", checkBox);
        checkBox = new JCheckBox("数据标签");
        panel.add(checkBox);
        comps.put("tag", checkBox);
        checkBox = new JCheckBox("数据标准");
        panel.add(checkBox);
        comps.put("standard", checkBox);
        checkBox = new JCheckBox("公共服务");
        panel.add(checkBox);
        comps.put("common", checkBox);
        JPanel apps = new JPanel(null);
        label = new JLabel("选择模块");
        label.setBounds(10, 5, 60, 20);
        apps.add(label);
        panel.setBounds(70, 5, 700, 70);
        apps.add(panel);
        apps.setBounds(10, 40, 760, 80);
        this.add(apps);

        panel = new JPanel(null);
        JButton button = new JButton("生成");
        button.setBounds(10, 5, 60, 30);
        panel.add(button);
        button.addActionListener(new GeneratorListener(this));

        JTextArea area = new JTextArea();
        area.setLineWrap(true);
        JScrollPane scrollPane = new JScrollPane(area);
        scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
        scrollPane.setBounds(80, 5, 660, 100);
        panel.setBounds(10, 120, 760, 120);
        this.add(panel);
        panel.add(scrollPane);
        comps.put("license", area);

        panel = new JPanel(null);
        button = new JButton("解析");
        button.setBounds(10, 5, 60, 30);
        button.addActionListener(new ParseListener(this));
        panel.add(button);
        area = new JTextArea();
        area.setLineWrap(true);
        scrollPane = new JScrollPane(area);
        scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
        scrollPane.setBounds(80, 5, 660, 100);
        panel.add(scrollPane);
        comps.put("show", area);
        panel.setBounds(10, 245, 760, 120);
        this.add(panel);

        this.setSize(800, 400);
        this.setResizable(false);
    }

    private Map<String, Component> comps = new HashMap<>();

    public Map<String, Component> getAllComponent() {
        return comps;
    }
}
